#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <windows.h>
int score;
short int heart, goal;
int sra1(int x)//随机数区间为[0,x]
{
	int result;
	srand((unsigned)time(NULL));
	result = rand() % (x++);
	return result;
}
int sra2(int a, int b)//随机数区间为[b,a+b-1]
{
	int result;
	srand((unsigned)time(NULL));
	result = rand() % a + b;
	return result;
}
int START()
{
	short int i, j = 1;
	char input;
	while (1)
	{
		system("cls");
		printf("                         #MUSIC GAME BUT NO MUSIC#\n                            -----------------\n");
		printf("                              Classic Mode");
		if (j == 1) printf("   @\n");
		else printf("\n");
		printf("                               Level Mode");
		if (j == 2) printf("    @\n");
		else printf("\n");
		printf("                              Custom Mode(?)");
		if (j == 3) printf(" @\n");
		else printf("\n");
		printf("                              How To Play It");
		if (j == 4) printf(" @\n");
		else printf("\n");
		printf("\n\n\n\n                            -----------------\n");
		printf("                            |VERSION  1.3.1|\n                            |MADE BY STARCH|");
		input = getch();
		if (input == 13 && j<4) j++;
		else if (input == 13 && j == 4) 
		{
			j = 1;
		}
		else if (input == ' ' && j == 1)
		{
			j=1;
			score = 0;
			return 1;
		}
		else if (input == ' ' && j == 2)
		{
			j=1;
			score = 0;
			return 2;
		}
		else if (input == ' ' && j == 3)
		{
			j=1;
			score = 0;
			return 3;
		}
		else if (input == ' ' && j == 4)
		{
			return 4;
		}
	}
}
int HOW()
{
	system("cls");
	printf("Press 'd' 'f' 'g' 'h' 'j' 'k' to get scores\n");
	system("pause");
	return 4;
}
int CLASSIC_MODE()
{
	short int k = 1,i;
	char temp, input;
	heart = 3;
	score = 0;
	while (1)
	{
		system("cls");
		if (k == 1)
		{
			k--;
			heart = 3;
		}
		goal = sra2(6,1);
		printf("\n\n\n\n\n\n\n				 Heart:%d Score:%d", heart, score);
		printf("\n				-----------------\n				");
		for (i = 0; i < 6; i++)
		{
			if ((i + 1) == goal)
			{
				printf("@@");
			}
			else
			{
				printf("##");
			}
			printf(" ");
			if (i == 5) printf("\n");
		}
		printf("				D |F |G |H |J |K |\n				-----------------");
		switch (goal)
		{
		case 1:temp = 'd'; break;
		case 2:temp = 'f'; break;
		case 3:temp = 'g'; break;
		case 4:temp = 'h'; break;
		case 5:temp = 'j'; break;
		case 6:temp = 'k'; break;
		}
		input = getch();
		if (input != temp)
		{
			heart--;
			if (heart <= 0)
			{
				system("cls");
				printf("\n\n\n\n\n\n                              You hava DEAD!\n");
				printf("                           Press '1' To Play Again.\n");
				printf("                           Press Other Key To Hub.\n");
				input = getch();
				if (input == '1')
				{
					heart = 3;
					return 1;//返回游戏
				}
				else
				{
					return 2;//大厅
				}
			}
		}
		else
		{
			score++;
		}
	}
}
int LEVEL_MODE()
{
	short int k = 1, j = 1, i;
	int arr_1[7] = { 1, 2, 3, 4, 5, 6, 0 };
	int level_bar = 0;
	char input, temp;
	LEVEL_START:
	while (1)
	{
		system("cls");
		printf("LEVEL 1");
		if (j == 1) printf(" @");
		else printf("\n");
		printf("BACK");
		if (j == 2) printf(" @");
		else printf("\n");
		input = getch();
		if (input == 13 && j<2) j++;
		else if (input == 13 && j >= 2) j = 1;
		else if (input == ' ' && j == 1) goto LEVEL_GAME;
		else if (input == ' ' && j == 2) return 1;
	}
	LEVEL_GAME:
	while (1)
	{
		system("cls");
		if (k == 1)
		{
			k--;
			heart = 3;
		}
		goal = arr_1[level_bar];
		if (goal == 0) return //--------------------TEMP----------------------
			level_bar++;
		printf("\n\n\n\n\n\n\n				 Heart:%d Score:%d", heart, score);
		printf("\n				-----------------\n				");
		for (i = 0; i < 6; i++)
		{
			if ((i + 1) == goal)
			{
				printf("@@");
			}
			else
			{
				printf("##");
			}
			printf(" ");
			if (i == 5) printf("\n");
		}
		printf("				D |F |G |H |J |K |\n				-----------------");
		switch (goal)
		{
		case 1:temp = 'd'; break;
		case 2:temp = 'f'; break;
		case 3:temp = 'g'; break;
		case 4:temp = 'h'; break;
		case 5:temp = 'j'; break;
		case 6:temp = 'k'; break;
		}
		input = getch();
		if (input != temp)
		{
			heart--;
			if (heart <= 0)
			{
				system("cls");
				printf("\n\n\n\n\n\n                              You hava DEAD!\n");
				printf("                           Press '1' To Play Again.\n");
				printf("                           Press Other Key To Hub.\n");
				input = getch();
				if (input == '1')
				{
					heart = 3;
					return 1;//返回游戏
				}
				else
				{
					return 2;//大厅
				}
			}
		}
		else
		{
			score++;
		}
	}
}
void main()
{
	short int sys = 1;
	short int CL_i, LE_i;
	MAIN:
	while (1)
	{
		sys=START();
		if (sys==1)
		{
			while(1)
			{
				CL_i = CLASSIC_MODE();
				if (CL_i == 1) continue;
				else if (CL_i == 2) goto MAIN;
			}
		}
		else if (sys == 2)
		{
			while (1)
			{
				LE_i = LEVEL_MODE();
				if (LE_i == 1) goto MAIN;
			}
		}
		else if (sys == 4)
		{
			HOW();
		}
	}
}